#!/usr/bin/perl 
use strict;
use DBI;
use CGI;
# use TTrakerSite;
use TTraker;

my $dbh;
initialize_dbi();

my $form_ref = &parse_input;
print_header();

my %FORM_DATA = %$form_ref;

my $num = $FORM_DATA{'empNum'};
my $name = $FORM_DATA{'empName'};
my $job = $FORM_DATA{'empJob'};
my $loc = $FORM_DATA{'empLoc'};
my $modNum = $FORM_DATA{'modNum'};
my @data;
my $message;

my $count = check_employee_number($modNum);
if ($count == 0) {
	my $msg = "No Employee Found with Number $modNum<br/>";
	select_employee_to_modify_msg ($num, $name, $msg);
} elsif ($count == 1) {
	my $data_ref = get_employee_data ($modNum);
	@data = @$data_ref;
	my $mNum = $data[0];
	my $mFir = $data[1];
	my $mLas = $data[2];
	my $mLoc = $data[3];
	my $mFac = $data[4];  		
	my $mAge = $data[5];
	my $mJob = $data[6];
	my $mPay = $data[7];
	my $mRat = $data[8];
	my $mLog = $data[9];
	my $mAct = $data[10];
#	print "$mNum, $mFir, $mLas, $mLoc, $mFac, $mAge, $mJob, $mPay, $mRat, $mLog, $mAct<br/>";	
	my $msg = "";
	modify_employee_data_msg ($mNum, $mFir, $mLas, $mLoc, $mFac, $mAge, $mJob, $mPay, $mRat, $mLog, $mAct, $msg);
}


db_disconnect();

##################### SUBROUTINES FOLLOW  #####################

sub select_employee_to_modify_msg
{
my $num = $_[0];
my $name = $_[1];
my $msg = $_[2];


print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_03_modify_employee_data</title>
</head>
<body onload='startUp1()'>
<h2><center>${banner}</center></h2>
<hr/>
<div id='clock'></div>
<div id='box1'>
Employee Number:<br/><br/>
Employee Name:<br/><br/>
</div>
<form id='box2' autocomplete='off' name='selectEmployee' action='${cgi_ref}trak_03_modify_employee_data.pl' method='post'>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>

<span>$num</span><br/><br/>
<span>$name</span></b><br/><br/>
<table>
	<tr>
		<td>Enter Employee Num: &nbsp</td>
		<td><input type="text" size=5 name=modNum /></td>
	</tr>
</table>
<br/>
<input type='submit' name='submit' value='Proceed'>
<br/><br/><br/>
<a href="${cgi_ref}trak_00_pay_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
<br/><br/>
<b id="warn">$msg</b>
</form>
</body>
</html>

ENDHEADER
}

sub modify_employee_data_msg
{
	my $mNum = $_[0];
	my $mFir = $_[1];
	my $mLas = $_[2];
	my $mLoc = $_[3];
	my $mFac = $_[4];  		
	my $mAge = $_[5];
	my $mJob = $_[6];
	my $mPay = $_[7];
	my $mRat = $_[8];
	my $mLog = $_[9];
	my $mAct = $_[10];
print <<ENDHEADER;
  <html>
  <head>
  <link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
  <script type='text/javascript' src='${js_ref}trak.js'></script>
  <title>trak_03_adm_add_new_client.pl</title>
  </head>
  <body>
  <h2><center>${banner}</center></h2>
  <hr/>
  <h3>Update Existing Employee Data</h3>
	<form id="box1Left" autocomplete="off" name="updateEmployee" action="${cgi_ref}trak_04_update_employee_date.pl" method="post">
	<input type="hidden" name=empNum value='$num'/>
	<input type="hidden" name=empName value='$name'/>
	<input type="hidden" name=empJob value='$job'/>
	<input type="hidden" name=empLoc value='$loc'/>
	<input type="hidden" name=mNum value='$mNum'/>
	<br/>
	<table>
		<tr>
			<td>Emp #: &nbsp</td>
			<td>$mNum &nbsp&nbsp</td>
		</tr>
		<tr>
			<td>First Name: &nbsp</td>
			<td><input type="text" value = "$mFir" size=24 name=mFir />&nbsp&nbsp</td>
		</tr>
		<tr>
			<td>Last Name: </td>
			<td><input type="text" value = "$mLas" size=24 name=mLas />&nbsp&nbsp</td>
		</tr>
		<tr>
		   <td>Login ID: </td>
		   <td><input type="text" value = "$mLog" size=24 name=mLog />&nbsp&nbsp</td>
		</tr>
		<tr>
			<td>Location: </td>
			<td><input type="text" value= "$mLoc" size=5 name=mLoc />&nbsp&nbsp</td>
		</tr>
		<tr>
   		<td>Facility #:</td>
   		<td><input type="text" value = "$mFac" size=5 name=mFac />&nbsp&nbsp</td>
   	<tr/>
		<tr>
   		<td>Agency:</td>
   		<td><input type="text" value = "$mAge" size=5 name=mAge />&nbsp&nbsp</td>
   	<tr/>
   	<tr>
	   	<td>Pay Cat: </td>
	   	<td><input type="text" value = "$mPay" size=5 name=mPay />&nbsp&nbsp</td>
		</tr>
		<tr>
	   	<td>Job: </td>
	   	<td><input type="text" value = "$mJob" size=5 name=mJob />&nbsp&nbsp</td>
		</tr>
		<tr>
   		<td>Rate: </td>
   		<td><input type="text" value = "$mRat"  size=5 name=mRat />&nbsp&nbsp<td>
		</tr>
		<tr>
   		<td>Active: </td>
   		<td><input type="text" value = "$mAct"  size=5 name=mAct />&nbsp&nbsp<td>
		</tr>
	</table>	
   	<br/>
   	<input type="submit" value="Update Employee Data">
   	<br/><br/>
    <a href="${cgi_ref}trak_00_pay_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
 	<br/><br/>
 	<b id="warn">$message</b><br/><br/>
 </form>
 </div>
 </body>
 </html>
ENDHEADER

}


